import { AxiosInstance} from 'axios';
import axios from 'axios'

const instance: AxiosInstance = axios.create({
  baseURL: 'http://localhost:8081/cart',
  timeout: 2000,
  headers: {
    'Content-type': 'application/json'
  },

  withCredentials: true
})

async function findMatchCarts(id: number) {
  let response = await instance.get('/', {
    params: {
      id
    }
  })

  return response.data
}

async function insertCart(item: CartItem) {
  let response = await instance.post('/', JSON.stringify(item))
  return response.data
}

async function deleteCart(id: number) {
  let response = await instance.delete('/', {
    params: {
      id: id
    }
  })

  return response.data
}

async function updateCart(item: CartItem) {
  let response = await instance.put('/', JSON.stringify(item))
  return response.data
}

export {
  findMatchCarts,
  insertCart,
  deleteCart,
  updateCart
}